package com.augn.service.impl;

import com.augn.entity.InvestmentProgress;
import com.augn.entity.InvestmentProgress;
import com.augn.entity.Result;
import com.augn.mapper.InvestmentProgressMapper;
import com.augn.service.IInvestmentProgressService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author augn
 * @since 2022-09-22
 */
@Service
public class InvestmentProgressServiceImpl extends ServiceImpl<InvestmentProgressMapper, InvestmentProgress> implements IInvestmentProgressService {

    @Autowired
    private InvestmentProgressMapper mapper;

    // 新增一个招商进度
    @Override
    public Result<?> insertOneInvestmentProgress(InvestmentProgress investmentProgress) {
        int insert = mapper.insert(investmentProgress);
        if (insert == 0) {
            return Result.error("-1", "新增失败");
        } else {
            return Result.success(insert);
        }
    }

    //删除一个招商进度
    @Override
    public Result<?> deleteOneInvestmentProgress(Integer id) {
        int delete = mapper.deleteById(id);
        if (delete == 0) {
            return Result.error("-1", "删除失败");
        } else {
            return Result.success(delete);
        }
    }

    //更新一个招商进度
    @Override
    public Result<?> updateOneInvestmentProgress(InvestmentProgress investmentProgress) {
        int update = mapper.updateById(investmentProgress);
        if (update == 0) {
            return Result.error("-1", "更新失败");
        } else {
            return Result.success(update);
        }
    }

    //获取一个招商进度
    @Override
    public Result<?> getOneInvestmentProgress(Integer id) {
        InvestmentProgress investmentProgress = mapper.getOneInvestmentProgress(id);
        return Result.success(investmentProgress);
    }

    //获取符合条件的招商进度
    @Override
    public List<InvestmentProgress> getPartInvestmentProgress() {
        QueryWrapper<InvestmentProgress> wrapper = new QueryWrapper<>();
        List<InvestmentProgress> investmentProgressList;
        investmentProgressList = mapper.selectList(wrapper);

        return investmentProgressList;

    }
}
